/**
 * Project Name:springBoot-model
 * File Name:TestValidResponse.java
 * Package Name:com.libra.model.vo
 * Date:2018年8月3日下午2:39:18
 * Copyright (c) 2018, wangzhch All Rights Reserved.
 *
*/

package com.libra.model.vo;

import java.io.Serializable;

import lombok.Data;

/**
 * ClassName:TestValidResponse <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:	 TODO ADD REASON. <br/>
 * Date:     2018年8月3日 下午2:39:18 <br/>
 * @author   wangzhch
 * @version  
 * @since    JDK 1.8
 * @see 	 
 */
@Data
public class ResponseData<T> implements Serializable {
	/**
	 * serialVersionUID:TODO(用一句话描述这个变量表示什么).
	 * @since JDK 1.8
	 */
	private static final long serialVersionUID = -2453069871528576229L;
	private String code;
	private String msg;
	private T data;
	public ResponseData() {
		super();
	}
	public ResponseData(String code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	/**
	 * 
	 * success:响应成功,不带响应数据. <br/>
	 * @author wangzhch
	 * @return
	 * @since JDK 1.8
	 */
	public static <T> ResponseData<T> success(){
		ResponseData<T> responseData = new ResponseData<T>();
		responseData.setCode("0000");
		responseData.setMsg("success");
		responseData.setData(null);
		return responseData;
	}
	
	/**
	 * 
	 * success:(响应成功,并附带详情msg). <br/>
	 * @author wangzhch
	 * @param msg
	 * @return
	 * @since JDK 1.8
	 */
	public static ResponseData success(String msg){
		ResponseData responseData = new ResponseData();
		responseData.setCode("0000");
		responseData.setMsg(msg);
		responseData.setData(null);
		return responseData;
	}
	/**
	 * 
	 * success:(响应成功,Data为一个响应结果的对象). <br/>
	 * @author wangzhch
	 * @param data
	 * @return
	 * @since JDK 1.8
	 */
	public static <T> ResponseData<?> success(T data){
		ResponseData<T> responseData = new ResponseData<>();
		responseData.setCode("0000");
		responseData.setMsg("success");
		responseData.setData(data);
		return responseData;
	}
	
	/**
	 * 
	 * error:(响应失败,但是不响应具体失败详情). <br/>
	 * @author wangzhch
	 * @return
	 * @since JDK 1.8
	 */
	public static ResponseData error(){
		ResponseData responseData = new ResponseData<>();
		responseData.setCode("500");
		responseData.setMsg("fail");
		responseData.setMsg(null);
		return responseData;
	}
	/**
	 * 
	 * error:(响应失败,并返回响应失败详情). <br/>
	 *
	 * @author wangzhch
	 * @param data
	 * @return
	 * @since JDK 1.8
	 */
	public static <T> ResponseData<?> error(T data){
		ResponseData<T> responseData = new ResponseData<>();
		responseData.setCode("500");
		responseData.setMsg("fail");
		responseData.setData(data);
		return responseData;
	}
	/**
	 * 
	 * error:(响应失败,返回错误信息msg). <br/>
	 * @author wangzhch
	 * @param msg  错误信息msg
	 * @return
	 * @since JDK 1.8
	 */
	public static ResponseData error(String msg){
		ResponseData responseData = new ResponseData();
		responseData.setCode("500");
		responseData.setMsg(msg);
		responseData.setData(null);
		return responseData;
	}
}

